package com.eric.windows.anima;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.TimeInterpolator;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.LinearLayout;
import android.widget.ImageView;

import com.eric.windows.R;

public class AnimatorSetTestActivity extends Activity implements View.OnClickListener {

    private LinearLayout container;
    private ImageView img;
    private AnimatorSet set;
    private ObjectAnimator objectAnimator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animator_set);

        container = (LinearLayout) findViewById(R.id.container);
        img = (ImageView) findViewById(R.id.img);
        findViewById(R.id.button).setOnClickListener(this);

        ObjectAnimator animator = ObjectAnimator.ofInt(container, "backgroundColor", 0xFFFF0000, 0xFFFF00FF);
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(img, "translationX", 0.0f, 200.0f, 0f);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(img, "scaleX", 1.0f, 2.0f);
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(img, "rotationX", 0.0f, 90.0f, 0.0F);
        ObjectAnimator animator4 = ObjectAnimator.ofFloat(img, "alpha", 1.0f, 0.2f, 1.0F);
        //组合动画方式1
        set = new AnimatorSet();
        set.play(animator)
                .with(animator1)
                .after(animator2)
                .after(animator3)
                .before(animator4);
        set.setDuration(5000);

//        set.playTogether(animator,animator1,animator2,animator3,animator4);

        PropertyValuesHolder valuesHolder = PropertyValuesHolder.ofFloat("translationX", 0.0f, 300.0f);
        PropertyValuesHolder valuesHolder1 = PropertyValuesHolder.ofFloat("scaleX", 1.0f, 1.5f);
        PropertyValuesHolder valuesHolder2 = PropertyValuesHolder.ofFloat("rotationX", 0.0f, 90.0f, 0.0F);
        PropertyValuesHolder valuesHolder3 = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.3f, 1.0F);
        objectAnimator = ObjectAnimator.ofPropertyValuesHolder(img, valuesHolder, valuesHolder1, valuesHolder2, valuesHolder3);
        objectAnimator.setDuration(2000);

        ViewPropertyAnimator viewPropertyAnimator = img.animate();
        viewPropertyAnimator.translationX(200).scaleX(2).setDuration(2000).start();


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button:
//                set.start();
                objectAnimator.start();
                break;
        }
    }
}
